package com.uedu.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.uedu.manager.StudentManager;
import com.uedu.vo.Student;


public class RegistServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//
		boolean flag = false ;

		String stu_number=request.getParameter("stu_number");
		String stu_name=request.getParameter("stu_name");
		String stu_sex=request.getParameter("stu_sex");
		String stu_passwd=request.getParameter("stu_passwd");

		Student student = new Student(stu_name,stu_number,stu_passwd,stu_sex);
		StudentManager studentManager = new StudentManager();

		flag = studentManager.regist(stu_name, stu_number, stu_passwd, stu_sex);

		if(flag == true){
			try {
								
				request.setAttribute("stu_number", stu_number);
				request.setAttribute("stu_sex", stu_sex);
				request.setAttribute("stu_name", stu_name);
				
				request.setAttribute("student", student);
				request.getRequestDispatcher("show.jsp").forward(request, response);
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
		}else{
			try {
				request.getRequestDispatcher("fail.jsp").forward(request,response);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
		}
		

	}
	
}
